package ThreadMethod;

public class TestYield {
    public static void main(String[] args) {
        Thread t1 =new Thread(new Task());
        t1.start();
        for (int i = 0; i <10 ; i++) {
            System.out.println(Thread.currentThread().getName()+"_-"+i);
            if (i %2== 0) {
                System.out.println("main主动放弃");
                Thread.yield();//主动放弃这次时间片,进入下一次时间片
            }
        }
    }
}
class Task implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"-"+i);
        }
    }
}
